package com.rpay.admin.util;

import com.rpay.admin.config.security.MyUserDetails;
import com.rpay.model.admin.RpayAdminUser;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 */
public class SessionUtil {


    public static RpayAdminUser getCurrentUser() {
        RpayAdminUser user = new RpayAdminUser();
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof MyUserDetails) {
            user = ((MyUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUser();

        }
        return user;
    }

    public static String getUsername() {
        RpayAdminUser user = getCurrentUser();
        return user.getUsername();
    }

    public static Long getUserId() {
        //return 22L;
        return getCurrentUser().getId();
    }

    public static Integer getUserType() {
        return (int) getCurrentUser().getUserType();
    }

    public static Long getOrgId() {
        return getCurrentUser().getOrgId();
    }

}
